<!-- article 添加界面-->

<!--region html模板-->
<div class="tableBox">

    <div class="x-nav">
        <div style="margin-bottom:20px;float:left">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>#(title)</legend>
            </fieldset>
        </div>

        <div class="layui-btn-group" style="line-height:1.6em;margin-top:3px;float:right">
            <button class="layui-btn layui-btn-sm layui-btn-primary">
                <i class="layui-icon">&#xe61f;</i>
                预留
            </button>
            <button class="layui-btn layui-btn-sm layui-btn-primary">
                <i class="layui-icon">&#xe640;</i>
                预留
            </button>
            <button class="layui-btn layui-btn-sm layui-btn-primary" data-type="ref">
                <i class="layui-icon">&#x1002;</i>
                刷新
            </button>
        </div>
    </div>

    <div class="x-body">
        <form class="layui-form layui-form-pane">


            #for(config:configList)
            <div class="layui-tab-item layui-show">

                <div class="layui-form-item">
                    <label class="layui-form-label">#(config.name)</label>
                    <div class="layui-input-inline">
                        <input name="name" value="#(config.value)"
                               placeholder="请输入#(config.name)" autocomplete="off"
                               class="layui-input" type="text">
                    </div>
                    <div class="layui-form-mid layui-word-aux">#(config.desc)</div>
                </div>

            </div>
            #end

            <!--<div class="layui-form-item" style="text-align: center">-->
                <!--<button class="layui-btn" lay-submit="" lay-filter="sendForm">保存</button>-->
            <!--</div>-->
        </form>

    </div>
</div>

<!--endregion-->

<script>
    layui.use(['element', 'form'], function () {
        var form = layui.form;


        //注意：parent 是 JS 自带的全局对象，可用于操作父页面
        var parentIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引

        //监听提交
        form.on('submit(sendForm)', function (data) {

            console.log(JSON.stringify(data.field));
            layui.$.ajax({
                type: "post",
                contentType: "application/json;charset=utf-8", // 因为上面是JSON数据
                url: '/admin/config/save',
                data: JSON.stringify(data.field),
                success: function (data) {

                    if (200 === data.code) {

                        //给父页面刷新
                        parent.layui.table.reload('table');
                        parent.layer.close(parentIndex);
                        parent.layer.msg('修改成功');

                    }

                    console.log(data);
                },
                error: function (data, textStatus, errorThrown) {
                    layer.msg("添加失败");
                    console.log(data);
                }
            });

            return false;
        });
    });
</script>
